
function ISPC() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
	let is_pc = true;
    if ((bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
        is_pc = false;
    }
	return is_pc;
}
let same_type = (a, b) => {
  if (a.info_group_type === b.info_group_type) {
    return true;
  }
  return false;
};
let same_no = (a, b) => {
  if (a.info_group_no === b.info_group_no) {
    return true;
  }
  return false;
};
let skip_type = a => {
  if (["table", "people_card"].indexOf(a.info_group_type) >= 0) {
    return false;
  }
  return true;
};

var ids = "";
function returnData(reports) {
  let item_p = {};
  let idx_arr = [];

  let table_obj_arr = [];
  let card_obj_arr = [];

  let table_obj = []; // for dev verbose
  let card_obj = []; // for dev verbose

  let objs = {};

  for (let i of reports.entries()) {
    let idx = i[0];
    let item = i[1];

    if (skip_type(item)) {
      item_p = item;
      table_obj = [];
      card_obj = [];
      continue;
    }

    let type_compare = same_type(item_p, item);
    let no_compare = same_no(item_p, item);

    // 类型和组号都一样
    if (type_compare && no_compare) {
      item_p = item;

      switch (item.info_group_type) {
        case "table":
          table_obj.push(item);
          break;
        case "people_card":
          card_obj.push(item);
          break;
        default:
          console.debug("skip");
      }

      continue;
    }

    // 类型和组号只要有一个不一样
    if (!type_compare || !no_compare) {
      idx_arr.push(idx);
      switch (item.info_group_type) {
        case "table":
          table_obj = [item];
          table_obj_arr.push({
            idx: idx,
            data: table_obj,
            info_category: item.info_category
          });
          objs[idx] = {
            info_group_type: "table_obj",
            data: table_obj,
            info_category: item.info_category
          };
          break;
        case "people_card":
          card_obj = [item];
          card_obj_arr.push({
            idx: idx,
            data: card_obj,
            info_category: item.info_category
          });
          objs[idx] = {
            info_group_type: "people_card_obj",
            data: card_obj,
            info_category: item.info_category
          };
          break;
        default:
          console.error("missing item");
          console.log(JSON.stringify(item));
      }
    }

    item_p = item;
  }

  let count = 0;
  for (let idx of idx_arr) {
    let offset_idx = idx + count;
    reports.splice(offset_idx, 0, objs[idx]);
    count += 1;
  }

  let people_inster = [];
  let ins_idex = null;
  for (let ins in reports) {
    if (reports[ins].info_group_type == "table_obj") {
      reports[ins]["data"] = _.chunk(reports[ins]["data"], 5);
    }
    if (reports[ins].info_group_type == "people_card_obj") {
			
      if (ins_idex != null) {
        reports[ins_idex]["obj"] = "show";
			
        // /reports[ins_idex]['data'].push(reports[ins]['data'])
        for (let s of reports[ins]["data"]) {
          people_inster.push(s);
        }
      } else {
        ins_idex = ins;
        reports[ins]["obj"] = "show";
        for (let s of reports[ins]["data"]) {
          people_inster.push(s);
        }
      }
    }
  }
	
  let PEOPLE_CHUNK_LENGTH = 7;
  reports[ins_idex]["data"] = _.chunk(people_inster, PEOPLE_CHUNK_LENGTH);
  reports[ins_idex]["chunk_data"] = _.chunk(
    _.chunk(people_inster, PEOPLE_CHUNK_LENGTH),
    2
  );

  return reports;
}



export const getBodyData=function(data){
	let datas = returnData(data);
	
	let respo = [];
	let risk = [];
	for (let k in datas) {
		if(datas[k].info_category == 'risk'){
			risk.push(datas[k]);
		}else{
			respo.push(datas[k])
		}
	}
	let return_data={
		data:respo,
		risk:risk
	}
	return return_data;
}

export const scroll=function(befor){
	
	let top = 520;
	if(!ISPC()){
		top = 1000;
	}
	if (document.getElementById("body-nav-bar") == null) {
		return;
	}
	if (befor > 150) {
		$("#roolto").css("display", "block");
	} else {
		$("#roolto").css("display", "none");
	}
	if(befor>top){
		$('.header-box').css('position','relative');
		$('#body-nav-bar').addClass('fixed_top');
	}else{
		$('.header-box').css('position','fixed');
		$('#body-nav-bar').removeClass('fixed_top');
	}
	let nav_class_count = document.getElementById("body-nav-bar").classList.length;
	$(".nav-item-ico a").each(function() {
		let id = $(this).attr("data-id");
		if ($("#" + id).offset()) {
			let yop = $("#" + id).offset().top;
			yop -= 115;
			if (yop < befor) {
				$(".nav-item-ico a").removeClass("active");
				$(this).addClass("active");
			}
		}
	})
	
}

export const MaoDian = function(e){
	 e = document.getElementById(e); /*以id命名的锚点*/
		if(!e){
			return false;
		}
	  let nav_class_count = document.getElementById('body-nav-bar').classList.length;
	
	 let y = e.offsetTop;
	  while ((e = e.offsetParent)) {
	    y += e.offsetTop;
	  }
	  y -= 100; /*悬浮菜单的高度*/
	  $("html, body").animate(
	    {
	      scrollTop: y
	    },
	    500
	  );
	  return false;
}
